package vmcs.entity;

import vmcs.observer.StoreItemChangeManager;
import vmcs.observer.StoreItemChangeManagerRegistry;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */
public class DrinksStoreItem extends StoreItem {

    public DrinksStoreItem(DrinksBrand ob, int qty) {
        super((StoreObject) ob, qty);
    }

    // OBSERVER IMPL BEGIN
    protected StoreItemChangeManager getStoreItemChangeManager() {
        return StoreItemChangeManagerRegistry.getManager(StoreItemChangeManagerRegistry.StoreItemType.Drink);
    }
    
    @Override
    public void setQuantity(int quantity) {
         this.quantity = quantity;
        // OBSERVER IMPL BEGIN
        System.out.println("CashStoreItem: Quantity set to " + quantity + " for store item " + this);
        // get change manager for this store item
        StoreItemChangeManager manager = getStoreItemChangeManager();
        // notify interested observers
        manager.notify(this, StoreItemChangeManager.EVENT_QUANTITYDRINKCHANGE);
        // OBSERVER IMPL END
    }
    
    public void decreaseQuantityByOne() {
        if(this.quantity > 0){
            setQuantity(this.quantity-1);
        }
    }
    
    public void setPrice(int p){
        DrinksBrand drink = (DrinksBrand) getContent(); 
        drink.setPrice(p);
         // OBSERVER IMPL BEGIN
        System.out.println("CashStoreItem: Quantity set to " + quantity + " for store item " + this);
        // get change manager for this store item
        StoreItemChangeManager manager = getStoreItemChangeManager();
        // notify interested observers
        manager.notify(this, StoreItemChangeManager.EVENT_DRINKVALUECHANGE);
        // OBSERVER IMPL END
    }
    // OBSERVER IMPL END
    
     public int getPrice () {
         DrinksBrand drink = (DrinksBrand) getContent(); 
        return drink.getPrice();
    }
     
    StoreItem checkDrinkbrand(String brand) {
        DrinksBrand drink = (DrinksBrand) this.getContent();
        if (drink.getName() == brand) {
            return this;
        } else {
            if (nextItem != null) {

                return ((DrinksStoreItem) nextItem).checkDrinkbrand(brand);
            } else {
                return null;
            }
        }
    }
  
}
